//
//  CTDisplayView.m
//  wuliangye
//
//  Created by jarze on 16/2/16.
//  Copyright © 2016年 jarze. All rights reserved.
//

#import "CTDisplayView.h"

#import <CoreText/CoreText.h>
@implementation CTDisplayView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetTextMatrix(context, CGAffineTransformIdentity);
    
//    移动函数
    CGContextTranslateCTM(context, 0, self.bounds.size.height);
//    缩放
    CGContextScaleCTM(context, 1.0, -1.0);
    
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddRect(path, NULL, self.bounds);
    
    
    NSAttributedString *attString = [[NSAttributedString alloc] initWithString:@"hello world"];
    CTFramesetterRef framesetter =  CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attString);
    CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, [attString length]), path, NULL);
    CTFrameDraw(frame, context);
    
    
    CFRelease(frame);
    CFRelease(path);
    CFRelease(framesetter);
    
}
@end
